package exercise10;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;

public class Exercise15_01 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Button button=new Button();
        button.setText("刷新");


        ArrayList<Integer> list=new ArrayList<>();
        for (int i=0;i<54;i++){
            list.add(i+1);
        }
        Collections.shuffle(list);



        HBox image_box=new HBox();
        BorderPane pane=new BorderPane();

        image_box.getChildren().clear();
        image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                File.separator+"veryhuo.com_pkp_"+list.get(0)+".jpg"));
        image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                File.separator+"veryhuo.com_pkp_"+list.get(1)+".jpg"));
        image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                File.separator+"veryhuo.com_pkp_"+list.get(2)+".jpg"));
        image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                File.separator+"veryhuo.com_pkp_"+list.get(3)+".jpg"));

        button.setOnAction(event -> {
            Collections.shuffle(list);
            image_box.getChildren().clear();
            image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                    File.separator+"veryhuo.com_pkp_"+list.get(0)+".jpg"));
            image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                    File.separator+"veryhuo.com_pkp_"+list.get(1)+".jpg"));
            image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                    File.separator+"veryhuo.com_pkp_"+list.get(2)+".jpg"));
            image_box.getChildren().add(new ImageView("file:image"+ File.separator+"card"+
                    File.separator+"veryhuo.com_pkp_"+list.get(3)+".jpg"));
        });


        pane.setTop(image_box);
        pane.setBottom(button);

        primaryStage.setTitle("扑克牌随机选择");
        primaryStage.setScene(new Scene(pane,600,300));
        primaryStage.show();
    }
}
